package com.yneusoft.manage.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.manage.model.param.*;
import com.yneusoft.manage.service.UserManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * @author: wjw
 * @date: 2021/10/20 15:14
 * @description:
 */
@RestController
@CrossOrigin
public class UserManageController {

    @Autowired
    private UserManageService userManageService;

    /**
     * 1.获取用户状态列表
     * @author: fzg
     * @return id 用户状态id; name 用户状态名称
     */
    @GetMapping("/userManage/getUserStateList")
    public ResponseWrapper getUserStateList(){
        return userManageService.getUserStateList();
    }

    /**
     * 2.获取用户列表
     * @author: fzg
     * @return rowNumber 查出来的总记录数
     *         list      用户列表
     */
    @GetMapping("/userManage/getUserList")
    public ResponseWrapper getUserList(@Validated SearchUserParam param){
        return userManageService.getUserList(param);
    }

    /**
     * 3.删除用户
     * @author: fzg
     * @param param DeleteUserParam
     */
    @PostMapping("/userManage/delUser")
    public ResponseWrapper delUser(@RequestBody @Validated DeleteUserParam param){
        return userManageService.delUser(param);
    }

    /**
     * 4.更改用户状态
     * @author: fzg
     * @param param ChangeUserStateParam类
     */
    @PostMapping("/userManage/changeState")
    public ResponseWrapper changeState(@RequestBody @Validated ChangeUserStateParam param){
        return userManageService.changeUserState(param);
    }

    /**
     * 5.【新增/修改】获取修改用户信息
     * @author: fzg
     * @param aid 用户aid
     * @return  name 用户名
     *          phone 手机号
     *          password 密码
     */
    @GetMapping("/userManage/userInfo")
    public ResponseWrapper userInfo(@NotNull(message = "用户aid不能为空") Integer aid){
        return userManageService.userInfo(aid);
    }

    /**
     * 6.【新增/修改】校验手机号是否存在
     * @author: fzg
     * @param param CheckPhoneParam类
     * @return  isExists 是否已存在【false：不存在，true：已存在】
     *          userInfo: name,phone,password
     */
    @GetMapping("/userManage/checkPhone")
    public ResponseWrapper checkPhone(@Validated CheckPhoneParam param){
        return userManageService.checkPhone(param);
    }

    /**
     * 7.【新增/修改】新增/修改用户信息（保存）
     * @author: fzg
     * @param param 参数类
     */
    @PostMapping("/userManage/saveUser")
    public ResponseWrapper saveUser(@RequestBody @Validated SaveUserParam param){
        return userManageService.saveUser(param);
    }

    /**
     * 8.【新增/修改】上传文件
     *
     * @param multipartFile 文件
     */

    @PostMapping(value = "/userManage//uploadFile")
    public ResponseWrapper upload(@RequestParam("file") MultipartFile multipartFile) {
        return userManageService.uploadFile(multipartFile);
    }

    /**
     * 9.【新增/修改】删除文件
     * @param param 附件id
     * @return message
     */
    @PostMapping("/userManage/delFile")
    public ResponseWrapper deleteFile(@RequestBody @Validated DeleteFileParam param){
        return userManageService.deleteFile(param);
    }

    /**
     * 10.下载文件
     *
     * @param response 响应对象，
     * @param  param 附件id
     */
    @PostMapping("/userManage/downloadFile")
    public Map<String,Object> down(HttpServletResponse response,@RequestBody @Validated DownloadFileParam param)  {
        return  userManageService.downloadFile(response,param);
    }

}
